my $file1=$ARGV[0];
my $file2=$ARGV[1];
open(FH,"<$file1") or die;
my @in1=<FH>;
chomp(@in1);
close(FH);
open(FH,"<$file2") or die;
my @in2=<FH>;
chomp(@in2);
close(FH);
my $count=0;
my $i=0;

foreach my $line1(@in1){
	if($i==0){
		$i++;
		next;
	}
	my @splitin1=split "\t",$line1;
print "@splitin1\n" if $splitin1[1] == 135374401;
	next if $splitin1[0] eq "chrX" or $splitin1[0] eq "chrY" or $splitin1[0] eq "chrM";
	my $j=0;
	foreach my $line2(@in2){
		if($j==0){
                	$j++;
                	next;
        	}	
		my @splitin2=split "\t",$line2;
		next if $splitin2[0] eq "chrX" or $splitin2[0] eq "chrY" or $splitin2[0] eq "chrM";
		if(($splitin1[0] eq $splitin2[0]) &&( ($splitin1[1] <= $splitin2[1] && $splitin1[2] >= $splitin2[2]) || ($splitin1[2] <= $splitin2[2] && $splitin1[2] >= $splitin2[1]) || ($splitin1[1] <= $splitin2[2] && $splitin1[1] >= $splitin2[1]))){
			$count++;
		}
	}	
}
print "overlap count is: $count\n";
